//
//  LLHomeHeaderView.m
//  BestLearning
//
//  Created by apple on 2017/2/20.
//  Copyright © 2017年 apple. All rights reserved.
//

#define titleFont [UIFont systemFontOfSize:15]
#define titleColor UIColor(0, 84, 173)

#import "LLHomeHeaderView.h"

@interface LLHomeHeaderView ()
/**
 标题图标
 */
@property(nonatomic, strong) UIImageView *titleImageView;
/**
 标题
 */
@property(nonatomic, strong) UILabel *titleLabel;
/**
 分割线
 */
@property(nonatomic, strong) UIView *lineView;

@property(nonatomic, strong) UIImageView *photoMageView;
/**
 标题
 */
@property(nonatomic, strong) UILabel *photoTitleLabel;



@end

@implementation LLHomeHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self == [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        //标题图表
        _titleImageView = [[UIImageView alloc]init];
        
        [self addSubview:_titleImageView];
        
        //标题
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = ColorRGB(0, 84, 173);
        _titleLabel.font = titleFont;
        [self addSubview:_titleLabel];
        
        //分割线
        _lineView = [[UILabel alloc]init];
        _lineView.backgroundColor = ColorRGB(249, 250, 250);
        [self addSubview:_lineView];
        
        self.moreButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        //[self.moreButton setTitle:@"查看分类  >" forState:(UIControlStateNormal)];
        self.moreButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.moreButton setTitleColor:ColorRGB(103, 102, 102) forState:(UIControlStateNormal)];
        [self addSubview:self.moreButton];
        
        
        self.nearView = [UIView new];
        self.nearView.hidden = YES;
        [self addSubview:self.nearView];
        
        self.photoMageView = [UIImageView new];
        self.photoMageView.image = [UIImage imageNamed:@"home_icon_near_class_default"];
        [self.nearView addSubview:self.photoMageView];
        
        self.photoTitleLabel = [UILabel new];
         self.photoTitleLabel.text = @"附近机构课堂";
        self.photoTitleLabel.textColor = ColorRGB(0, 84, 173);
        self.photoTitleLabel.font = titleFont;
        [self.nearView addSubview:self.photoTitleLabel];
        
        
        
        
        
        
    }
    return self;
    
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    
    //标题图表
    [_titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    //标题
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleImageView.mas_right).offset(10);
        make.centerY.equalTo(_titleImageView.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(160, 20));
    }];
    
    
    [self.nearView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(-25);
        make.top.equalTo(self.titleLabel);
        make.height.equalTo(self.titleLabel);
        make.width.offset(100);
        
        
        
    }];
    
    
    [self.photoMageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.equalTo(self.nearView);
        
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
   
    [self.photoTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photoMageView.mas_right).offset(10);
        make.centerY.equalTo(self.photoMageView.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(100, 20));
       
    }];
    
    
    
    
    
    
    
    [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-8);
        make.top.equalTo(self.titleImageView);
    }];
    
    //分割线
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(_titleLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(kScreenWidth, 1));
    }];
    

}

-(void)setTitleImage:(NSString *)imageName andTitle:(NSString *)title seeName:(NSString *)name{
    
    self.titleImageView.image = [UIImage imageNamed:imageName];

    self.titleLabel.text = title;
    self.titleLabel.textColor = ColorRGB(0, 171, 227);
    [self.moreButton setTitle:name forState:(UIControlStateNormal)];
}
@end
